package com.zhou.common.mybatis.template.shiro.controller;

import com.zhou.common.lib.model.Response;
import com.zhou.common.lib.util.StringUtils;
import com.zhou.common.mybatis.template.shiro.config.shiro.service.SysRegisterService;
import com.zhou.common.mybatis.template.shiro.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 注册验证
 *
 * @author ruoyi
 */
@Controller
public class SysRegisterController {
    @Autowired
    private SysRegisterService registerService;

    @Value("${shiro.enable.registerUser:true}")
    private Boolean enableRegisterUser;

    @GetMapping("/register")
    public String register() {
        return "register";
    }

    @PostMapping("/register")
    @ResponseBody
    public Response ajaxRegister(SysUser user) {
        if (!enableRegisterUser) {
            return Response.error("当前系统没有开启注册功能！");
        }
        String msg = registerService.register(user);
        return StringUtils.isEmpty(msg) ? Response.success() : Response.error(msg);
    }
}
